﻿using System;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace fonttest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private MainViewModel _context;

        public MainWindow()
        {
            InitializeComponent();
            string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"../../simkai.ttf");
            this.DataContext = _context = new MainViewModel(path, 300);
            _context.PropertyChanged += OnContextPropertyChanged;
        }

        void OnContextPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "CanvasItems")
            {
                _canvas.Children.Clear();

                foreach (var item in _context.CanvasItems)
                {
                    _canvas.Children.Add(new Path() { Stroke = item.Stroke, Fill = item.Fill, Data = item.Glyph });
                }
            }
        }

        private void OnLoad(object sender, RoutedEventArgs e)
        {
        }

        private void OnSave(object sender, RoutedEventArgs e)
        {
        }

        private void OnPrev(object sender, RoutedEventArgs e)
        {
            _context.Prev();
        }

        private void OnNext(object sender, RoutedEventArgs e)
        {
            _context.Next();
        }

        private void Canvas_MouseDown(object sender, MouseButtonEventArgs e)
        {
            _context.MouseDown(e.GetPosition(_canvas));
        }

        private void Canvas_MouseUp(object sender, MouseButtonEventArgs e)
        {
            _context.MouseUp(e.GetPosition(_canvas));
        }

        private void Canvas_MouseMove(object sender, MouseEventArgs e)
        {
            _context.MouseMove(e.GetPosition(_canvas), e.LeftButton == MouseButtonState.Pressed);
        }
    }
}
